package org.zsl.controller.springmvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zsl.model.ResponseMessage;
import org.zsl.model.User;
import org.zsl.service.UserService2;

import java.util.List;

@RestController
public class RestfulController {
    @Autowired
    private UserService2 userService2;

  //  @RequestMapping(value = "/add",method = RequestMethod.POST)
    @PostMapping("/add")
    public ResponseMessage addUser(User user){

        return  userService2.editUser(user);

    }



 //   @RequestMapping(value = "/edit",method = RequestMethod.PUT)
    @PutMapping("/edit")
    public ResponseMessage editUser(User user){

        return  userService2.editUser(user);

    }


    /**
     *   1. 删除
     *       物理删除
     *       逻辑删除
     *          历史数据  ---> 转移到别的表，或者数据库中
     * */
  // @RequestMapping(value = "/remove/{userid}",method = RequestMethod.DELETE)
    @DeleteMapping("/remove/{userid}")
    public ResponseMessage removeUser(@PathVariable("userid") Integer userId){

        System.out.println("userid:"+userId);
        return  userService2.removeUser(userId);

    }


  //  @RequestMapping(value = "/get/{userid}",method = RequestMethod.GET)
    @GetMapping("/get/{userId}")
    public User getSingel(@PathVariable("userid") Integer userId){
        System.out.println("userid:"+userId);
        return  userService2.getSingle(userId);
    }


   // @RequestMapping(value = "/list",method = RequestMethod.GET)
    @GetMapping("/list")
    public List<User> getList(){

        return  userService2.getList();
    }


}
